<template>
  <div
    ref="barchart"
    class="bar-chart"
  ></div>
</template>

<script>
import { title } from "@/settings";
export default {
  props: {
    chartData: {
      type: Object,
      default: () => {},
    },
    stype: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      chart: null,
      title: "",
      barIndex: "",
      data1: [],
      data2: [],
      clickFlag: true,
      barChartDataUrl: "",
    };
  },
  watch: {
    chartData() {
      this.initChart();
    },
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  mounted() {
    this.initChart();
  },
  methods: {
    initChart() {
      this.chart = this.$echarts.init(this.$refs.barchart);
      let option = this.getOption();
      this.chart.setOption(option);
      this.chart.resize();
      this.barChartDataUrl = this.chart.getDataURL();
    },
    getOption() {
      let option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value',
          boundaryGap: [0, 0.01]
        },
        yAxis: {
          type: 'category',
          data: this.chartData.educationName
        },
        series: [
          {
            name: '',
            type: 'bar',
            label: {
              show: true,
              position:'right'
            },
            data: this.chartData.educationCount
          },
        ]
      };

      return option;
    },
  },
};
</script>

<style lang="scss" scoped>
.bar-chart {
  width: 100%;
  height: 100%;
  margin-top: 20px;
}
</style>
